package com.viser.partyinrs.entities;

import java.io.Serializable;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Post implements Serializable, Comparable<Post> {
	private static final long serialVersionUID = 1000006L;
	
	public String username = "";  // Username korisnika koji je ostavio post
	public int redniBroj = 0;
	public String nazivMesto = "";
	public double geoX = 0;
	public double geoY = 0;
	public String opis = "";
	public String datumVreme = "";  // "yyyy/MM/dd HH:mm:ss" <-- mora ovako!
	
	public Post()
	{
		super();
	}
	
	public Post(String username, int redniBroj, String nazivMesto, double geoX, double geoY, String opis, String datumVreme) {
		super();
		this.username = username;
		this.redniBroj = redniBroj;
		this.nazivMesto = nazivMesto;
		this.geoX = geoX;
		this.geoY = geoY;
		this.opis = opis;
		this.datumVreme = datumVreme;
	}

	@Override
	public int compareTo(Post drugi) {
		Date ovoVreme = new Date();
		SimpleDateFormat sdf1 = new SimpleDateFormat();
		sdf1.applyPattern("yyyy/MM/dd HH:mm:ss");
		try {
			ovoVreme = sdf1.parse(this.datumVreme);
		} catch (ParseException e1) {
			e1.printStackTrace();
		}
		
		Date drugoVreme = new Date();
		SimpleDateFormat sdf2 = new SimpleDateFormat();
		sdf2.applyPattern("yyyy/MM/dd HH:mm:ss");
		try {
			drugoVreme = sdf2.parse(drugi.datumVreme);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		
		return ovoVreme.compareTo(drugoVreme);
	}	
}
